package com.example.administrator.widget;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity {
    private List<Imagetext> imagetextList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recycleview_layout);

        init();

        android.support.v7.widget.RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycle_view);
        LinearLayoutManager layoutManager=new LinearLayoutManager(this);
        //横向列表
        //layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //网格布局的列表
        //GridLayoutManager layoutManager=new GridLayoutManager ( this,3 );
        //分割线设置
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));

        recyclerView.setLayoutManager(layoutManager);
        RecyclerViewAdapter adapter=new RecyclerViewAdapter(imagetextList);
        recyclerView.setAdapter (adapter);

    }

    private void init(){
        for (int i=0;i<5;i++){
            Imagetext a = new Imagetext("one",R.mipmap.ic_launcher);
            imagetextList.add(a);
            Imagetext b = new Imagetext("two",R.mipmap.ic_launcher);
            imagetextList.add(b);
            Imagetext c = new Imagetext("three",R.mipmap.ic_launcher);
            imagetextList.add(c);
            Imagetext d = new Imagetext("four",R.mipmap.ic_launcher);
            imagetextList.add(d);
            Imagetext e = new Imagetext("five",R.mipmap.ic_launcher);
            imagetextList.add(e);
            Imagetext f = new Imagetext("six",R.mipmap.ic_launcher);
            imagetextList.add(f);
        }
    }
}


